﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
namespace EDMS.Users
{
    public partial class UserShow : System.Web.UI.Page
    {
        private int _count;

        public int Count
        {
            get { return _count; }
            set { _count = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (DataClassesDataContext lqDB = new DataClassesDataContext())
            {
                gvShow.DataSource = lqDB.User;
                gvShow.KeyFieldName = "ID";
                gvShow.DataBind();
                Count = lqDB.User.Count();

            }
        }
        //删除
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            LinkButton li = (LinkButton)sender;
            int id = Convert.ToInt32(li.CommandArgument);
            using (DataClassesDataContext lqDB = new DataClassesDataContext())
            {
                var result = lqDB.User.FirstOrDefault(r => r.ID == id);
                if (result != null)
                {
                    lqDB.User.DeleteOnSubmit(result);
                    lqDB.SubmitChanges();
                    Response.Write("<script>alert('删除成功！');location.href='UserShow.aspx';</script>");
                }


            }
        }
    }
}